package com.vm.common;

import java.util.List;

import jxl.format.UnderlineStyle;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

/**
 * jxl基本�?
 * 
 * @author tzh 2010-7-31
 * 
 */
public class JXLUtil {

	/**
	 * * 创建�?�� WritableSheet,并对第一行的标题进行样式设置
	 * 
	 * @param book WritableWorkbook
	 * @param name WritableSheet�?
	 * @param labelList 要显示的标题
	 * @return
	 * @throws RowsExceededException
	 */
	public static WritableSheet getWritableSheet(WritableWorkbook book, String name, List labelList) throws RowsExceededException {
		WritableSheet sheet = book.createSheet(name, 0);
		sheet.setRowView(0, 600);
		if (labelList != null) {
			for (int i = 1; i <= labelList.size(); i++) {
				sheet.setRowView(i, 450);
			}
		}
		return sheet;
	}

	/**
	 * 得到标题行的显示样工
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getTitleWritableCellFormat() throws WriteException {
		WritableFont titleWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat titleWCF = new WritableCellFormat(titleWF); // 单元格定�?
		titleWCF.setBackground(jxl.format.Colour.GRAY_25); // 设置单元格的背景颜色
		titleWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		titleWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		titleWCF.setIndentation(0);
		titleWCF.setWrap(true);
		return titleWCF;
	}

	/**
	 * 得到标题行的显示样工
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getPortInfoTitleWritableCellFormat() throws WriteException {
		WritableFont titleWF = new WritableFont(WritableFont.ARIAL, 14, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat titleWCF = new WritableCellFormat(titleWF); // 单元格定�?
		titleWCF.setBackground(jxl.format.Colour.GRAY_50); // 设置单元格的背景颜色
		titleWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		titleWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		titleWCF.setIndentation(0);
		return titleWCF;
	}
	
	/**
	 * 得到泊位名称要显示的样式
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getPortInfo_NameWritableCellFormat() throws WriteException {

		WritableFont bodyWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat bodyWCF = new WritableCellFormat(bodyWF); // 单元格定�?
//		bodyWCF.setBackground(jxl.format.Colour.GREEN); // 设置单元格的背景颜色
//		bodyWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		bodyWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		bodyWCF.setIndentation(0);
		bodyWCF.setWrap(true);
		return bodyWCF;
	}
	
	/**
	 * 得到船舶名称要显示的样式
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getShipNameWritableCellFormat() throws WriteException {

		WritableFont bodyWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat bodyWCF = new WritableCellFormat(bodyWF); // 单元格定�?
//		bodyWCF.setBackground(jxl.format.Colour.getInternalColour(16777215)); // 设置单元格的背景颜色
//		bodyWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		bodyWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		bodyWCF.setIndentation(0);
		bodyWCF.setWrap(true);
		return bodyWCF;
	}
	
	/**
	 * 得到内容行要显示的样�?
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getBodyWritableCellFormat() throws WriteException {

		WritableFont bodyWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat bodyWCF = new WritableCellFormat(bodyWF); // 单元格定�?
		// bodyWCF.setBackground(jxl.format.Colour.GRAY_25); // 设置单元格的背景颜色
		bodyWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		bodyWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		bodyWCF.setIndentation(0);
		bodyWCF.setWrap(true);
		return bodyWCF;
	}
	
	/**
	 * 得到统计行要显示的样�?
	 * 
	 * @return
	 * @throws WriteException
	 */
	public static WritableCellFormat getCountWritableCellFormat() throws WriteException {

		WritableFont bodyWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); // 定义格式 字体 下划�?斜体 粗体 颜色
		WritableCellFormat bodyWCF = new WritableCellFormat(bodyWF); // 单元格定�?
		 bodyWCF.setBackground(jxl.format.Colour.ORANGE); // 设置单元格的背景颜色
		// bodyWCF.setAlignment(jxl.format.Alignment.CENTRE); // 设置对齐方式
		bodyWCF.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
		bodyWCF.setIndentation(0);
		return bodyWCF;
	}

}
